<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Setting extends CI_Controller {
	function __construct(){
		parent::__construct();
		$this->load->library('Huashang/wechat');
		$this->load->library('Huashang/system');
		$this->system->checkLogin();
	}
	//基本信息入口
	public function index(){
		$data['rs']=array_pop($this->system->settings(false));
		$this->load->view('setting/index',$data);
	}

	//站点配置
	public function site_set(){
		$this->load->view('setting/site_set');
	}

    //网站信息
    public function site_information(){
        $this->load->view('setting/site_information');
    }

    //支付信息
    public function pay_information(){
        $this->load->view('setting/pay_information');
    }

	//文章管理
	public function article_manage(){
		$this->load->view('setting/article_manage');
	}

	//文章管理列表
	public function get_article_list()
    {
        echo json_encode(
            array(
                'total' =>  9,
                'rows'  =>  array(
                    array('id'=>1, 'code_name'=>'关于我们(103)', 'title'=>'关于我们', 'sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>2, 'code_name'=>'联系我们(104)', 'title'=>'联系我们', 'sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>3, 'code_name'=>'代理联盟(105)', 'title'=>'代理联盟', 'sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>4, 'code_name'=>'联盟协议(106)', 'title'=>'联盟协议', 'sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>5, 'code_name'=>'存款帮助(107)', 'title'=>'存款帮助', 'sort'=>0,'status'=>'审核中', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>6,'code_name'=>'取款帮助(108)', 'title'=>'取款帮助', 'sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>7, 'code_name'=>'常见问题(109)', 'title'=>'常见问题', 'sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>8, 'code_name'=>'会员注册(110)', 'title'=>'会员注册', 'sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>9, 'code_name'=>'代理注册(111)', 'title'=>'代理注册', 'sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>8, 'code_name'=>'开户协议(112)', 'title'=>'开户协议', 'sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>9, 'code_name'=>'自定义(113)', 'title'=>'自定义', 'sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                )
            ), JSON_UNESCAPED_UNICODE);
	}

	//文章管理 --设置内容
		public function article_con_set(){
			$this->load->view('setting/article_con_set');
		}

	//广告管理
	public function advertise_manage(){
		$this->load->view('setting/advertise_manage');
	}

	//广告管理列表
	public function get_advertise_list()
    {
        echo json_encode(
            array(
                'total' =>  18,
                'rows'  =>  array(
                    array('id'=>1,'code_name'=>11, 'advertise_name'=>'首页幻灯一', 'img'=>'/site_info/1/img/flash20170226115542.png','img_title'=>'首页幻灯一','sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>2, 'code_name'=>12, 'advertise_name'=>'首页幻灯二', 'img'=>'/site_info/1/img/flash20170226115542.png','img_title'=>'首页幻灯二','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>3, 'code_name'=>13, 'advertise_name'=>'首页幻灯三', 'img'=>'/site_info/1/img/flash20170226115542.png','img_title'=>'首页幻灯三','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>4, 'code_name'=>14, 'advertise_name'=>'首页幻灯四', 'img'=>'','img_title'=>'首页幻灯四','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>5, 'code_name'=>15, 'advertise_name'=>'首页幻灯五', 'img'=>'','img_title'=>'首页幻灯五','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>6, 'code_name'=>16, 'advertise_name'=>'首页LOGO', 'img'=>'','img_title'=>'首页LOGO','sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>7, 'code_name'=>17, 'advertise_name'=>'首页弹窗广告', 'img'=>'','img_title'=>'首页弹窗广告','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>8, 'code_name'=>18, 'advertise_name'=>'左下角广告', 'img'=>'','img_title'=>'左下角广告','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>9,'code_name'=>19, 'advertise_name'=>'左浮动广告', 'img'=>'','img_title'=>'左浮动广告','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>10, 'code_name'=>20, 'advertise_name'=>'右浮动广告', 'img'=>'','img_title'=>'右浮动广告','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>11,'code_name'=>21, 'advertise_name'=>'会员中心LOGO', 'img'=>'','img_title'=>'会员中心LOGO','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>12, 'code_name'=>22, 'advertise_name'=>'手机版LOGO', 'img'=>'/site_info/1/img/flash20170226115542.png','img_title'=>'手机版LOGO','sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>13, 'code_name'=>23, 'advertise_name'=>'手机轮播一', 'img'=>'/site_info/1/img/flash20170226115542.png','img_title'=>'手机轮播一','sort'=>0,'status'=>'启用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>14, 'code_name'=>24, 'advertise_name'=>'手机轮播二', 'img'=>'','img_title'=>'手机轮播二','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>15, 'code_name'=>25, 'advertise_name'=>'手机轮播三', 'img'=>'','img_title'=>'手机轮播三','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>16, 'code_name'=>26, 'advertise_name'=>'手机轮播四', 'img'=>'','img_title'=>'手机轮播四','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>17, 'code_name'=>27, 'advertise_name'=>'手机轮播五', 'img'=>'','img_title'=>'手机轮播五','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s')),
                    array('id'=>18, 'code_name'=>28, 'advertise_name'=>'右下角广告', 'img'=>'','img_title'=>'右下角广告','sort'=>0,'status'=>'禁用', 'join_time'=>date('Y-m-d H:i:s'), 'revise_time'=>date('Y-m-d H:i:s'))
               	)
            ), JSON_UNESCAPED_UNICODE);
	}

	//广告管理 --设置内容
		public function advertise_con_set(){
			$this->load->view('setting/advertise_con_set');
		}

    //广告管理 --上传图片
    public function logo_up(){
        $this->load->view('setting/logo_up');
    }

	//活动管理
	public function activity_manage(){
        $data['auth']=explode(',', $this->input->get('auth'));
		$this->load->view('setting/activity_manage',$data);
	}

	//活动管理列表
    public function get_activity_list()
    {
       echo '{"total":0,"rows":[{"id":1,"picture":"","title":"中秋佳节活动","position":"PC端","release_time":"未设置","deadline":"未设置"}]}';
	}

	//活动管理 --设置内容
	public function activity_con_set(){
		$this->load->view('setting/activity_con_set');
	}

	//保存基本信息
	public function savebasic(){
		$this->system->savebasic();
	}

	//加载菜单模块
	public function module(){
		$data['name']=$this->input->get('name');
		$data['tag']=$this->input->get('tag');
		$data['type']=$this->input->get('type');
		$data['app']=$this->input->get('app');
		$data['sys']=$this->config->item('system_modules');
		$site = array_pop($this->wechat->user_info($this->session->userdata('wechat_id')));
		foreach($data['sys'] as $k=>$v){
			$data['sys'][$k]['url']=str_replace('{SN}',$site['sn'],$v['url']);
		}
		$arr=array_pop($this->wechat->module());
		foreach($arr as $k=>$v){
			$data['guest'][] = $v;
			$data['guest'][$k]['type'] = $this->view_type($v['type']);
			$data['guest'][$k]['url']  = $v['external_url'];//$v['type']==3?$v['external_url']:str_replace('/admin/','/wechat',WEB)."/$v[en_name].html?sn=".$site['sn'];
		}
		$this->load->view('setting/module',$data);
	}
	private function view_type($id){
		if($id==1||$id==3) return 'view';
		if($id==2||$id==4) return 'click';
	}

	//域名列表
    public function site_domain()
    {
        $data = array();

        $this->load->view('setting/domain', $data);
    }

    public function get_site_domain_list()
    {
        echo <<<content
{
    "total": 1, 
    "rows": [
        {
            "id": 1,
            "is_main": "【主】",
            "domain": "www.baidu.com",
            "is_bind": "【已绑】",
            "cname":"lliqoaj-kqkoa.baidu.com",
            "add_date":"2017-3-18",
            "op":"kojjja",
            "can_edit":0
        },
                {
            "id": 2,
            "is_main": "【备】",
            "domain": "www.baidu.com",
            "is_bind": "【未绑】",
            "cname":"lliqoaj-kqkoa.baidu.com",
            "add_date":"2017-3-18",
            "op":"kojjja",
            "can_edit":1
        }
    ]
}
content;

    }

    public function pay_domain()
    {
        $data = array();

        $this->load->view('setting/pay_domain', $data);
    }

    public function add_domain()
    {
        $data = array();

        $this->load->view('setting/add_domain', $data);
    }

    public function get_pay_domain_list()
    {
        echo <<<content
{
    "total": 1, 
    "rows": [
        {
            "id": 1,
            "is_main": "【主】",
            "domain": "www.baidu.com",
            "is_bind": "已绑",
            "cname":"lliqoaj-kqkoa.baidu.com",
            "add_date":"2017-3-18",
            "op":"kojjja",
            "can_edit":0
        },
                {
            "id": 2,
            "is_main": "【备】",
            "domain": "www.baidu.com",
            "is_bind": "未绑",
            "cname":"lliqoaj-kqkoa.baidu.com",
            "add_date":"2017-3-18",
            "op":"kojjja",
            "can_edit":1
        }
    ]
}
content;

    }

}